package com.perfect.service;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.perfect.base.BaseService;
import com.perfect.dao.DiscountMapper;
import com.perfect.model.DiscountDataModel;
import com.perfect.model.DiscountModel;
import com.perfect.query.DiscountQuery;
import com.perfect.vo.Discount;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 优惠券Service
 */
@Service
public class DiscountService extends BaseService<Discount,Integer> {

    @Resource
    private DiscountMapper discountMapper;

    /**
     * 多条件查询
     * @param discountQuery
     * @return
     */
    public Map<String, Object> listDiscountByParams(DiscountQuery discountQuery){
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(discountQuery.getPage(), discountQuery.getLimit());
        PageInfo<DiscountModel> pageInfo = new PageInfo<>(discountMapper.selectDiscountlistByParams(discountQuery));
        map.put("code", 0);
        map.put("msg", "suceess");
        map.put("count", pageInfo.getTotal());
        map.put("data", pageInfo.getList());
        return map;

        
    };

    /**
     * 查询优惠券类型
     * @return
     */
    public List<Map<String,Object>> listDiscountType(){
        return discountMapper.selectDiscountType();
    }

    /**
     * 查询优惠券详情
     */
    public DiscountDataModel listDiscountDataById(Integer id){
        return discountMapper.selectDiscountDataById(id);
    }

}
